package Gui;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import Logic.LoginInfo;
import client.ClientHendler;
import client.LibaryMain;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
/**
 * this class implements the workers window 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class Workers extends JPanel {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static int k=1;

	/**
	 * constractor of workers window 
	 * @param str
	 */
	public Workers(String[] str) {
		
		initcomponents(str);
		MainScreen.card.add("WORKERS", this);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(Workers.class.getResource("/Gui/images/staff.png")));
		label.setBounds(259, 383, 688, 342);
		add(label);
		MainScreen.cardLayot.show(MainScreen.card, "WORKERS");
		
	}
/**
 * initilize  the workers window 
 * @param str
 */
	public void initcomponents(String[] str)
	{
	setBackground(new Color(153, 204, 255));

	 System.out.println("pitka33");

	JLabel lblLendingReport = new JLabel("Workers");
	lblLendingReport.setBounds(71, 26, 221, 32);
	lblLendingReport.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
	
	JButton btnBack = new JButton("Back");
	btnBack.setBounds(120, 567, 97, 25);
	btnBack.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			
			MainScreen.cardLayot.show(MainScreen.card,"DirectorWindow");

		}
	});
	
	
	btnBack.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
	
	JButton btnLogout = new JButton("Logout");
	btnLogout.setBounds(757, 567, 97, 25);
	btnLogout.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
	
	Vector<String> title = new Vector<String>();
	title.add("WorkerID");
	title.add("Password");
	title.add("First Name");
	title.add("Last Name");
    title.add("Email");
	setLayout(null);
	add(lblLendingReport);
	add(btnBack);
	add(btnLogout);
	
	Vector<Vector<Object>> data = new Vector<Vector<Object>>();
	
	 for (int i=1; i<=(str.length-5);i=i+5){
	        Vector<Object> row = creatrow(str,i);
	        data.add(row);
	        }
	
	
	JScrollPane scrollPane = new JScrollPane();
	scrollPane.setBounds(159, 89, 657, 315);
	add(scrollPane);
	final JTable table = new JTable(data, title);
	scrollPane.setViewportView(table);
	table.setBorder(UIManager.getBorder("Tree.editorBorder"));
	table.setColumnSelectionAllowed(true);
	table.setCellSelectionEnabled(true);
	table.setFont(new Font("Times New Roman", Font.PLAIN, 15));
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.setPreferredScrollableViewportSize(new Dimension(500 , 50));
	table.setFillsViewportHeight(true);
	btnLogout.addActionListener(new java.awt.event.ActionListener() {      
        public void actionPerformed(java.awt.event.ActionEvent ev) {
        	btnLogOut(ev);				
		}
        
		private void btnLogOut(ActionEvent ev) {
			ArrayList<String> Arr=new ArrayList<String>();
			Arr.add("Logout");
			Arr.add("Worker");
			Arr.add(LoginInfo.UserName);
			LibaryMain.chat.handleMessageFromGui(Arr);
			MainScreen.cardLayot.show(MainScreen.card, "Login");
			
		}
    });

	}	


	private Vector<Object> creatrow(String[] str,int i) {
		Vector<Object> row = new Vector<Object>();
 		row.add( ""+str[i]);
        row.add( ""+str[i+1]);
        row.add( ""+str[i+2]);
        row.add( ""+str[i+3]);
        row.add( ""+str[i+4]);
		return row;
	}
	
}
